using SQLRunnerLib.Services;
using SQLServices.Runners;
using SQLServices.Runners.Events;

namespace SQLRunnerLib.TransMgr
{
    /// <summary>
    /// Use this implementation if you dont need a transaction when executing the scripts but
    /// you want to be sure that you isolate the scripts from each other.
    /// This manager creates a new connection for each script so it does not perform as well as the
    /// Naive implementation but it does not have the problem where a script starts a transaction that
    /// is not commited which means that updates are lost when the connection closes.
    /// </summary>
    class StrictConnMgr:PessimistConnMgr
    {
        public StrictConnMgr(IRunner runner) : base(runner)
        {
        }

        /// <summary>
        /// Called after a script has been executed.
        /// This manager closes the connection once the script is executed
        /// </summary>
        protected override void OnScriptExecuted(object sender, ScriptExecutedEventArgs e)
        {
            CleanConnection();
        }

        /// <summary>
        /// When the Runner has finished the execution of all scripts it calls this method.
        /// In this implementation the connection is closed.
        /// </summary>
        protected override void OnExecutionFinished(object sender, ExecutionFinishedEventArgs e)
        {
            return;
        }

    }
}
